#ifndef _IIC_h_
#define	_IIC_h_

#include "define.h"


#define		IIC_DeviceAddr		0X72	//0x72//
#define		ERROR_HEAD 			3	//	

#define		IIC_TIMEOUT 		25

#define		FRAME_END			0X7B	//0X54//0x7a	//Slave Address  
#define		DEVICE_ID			0X72	//0X54//0x7a	//Slave Address  
#define		COMMEND_INIT_ID		0X01	//
#define		COMMEND_WORK_ID0	0X11	//
#define		COMMEND_WORK_ID1	0X12	//

#define		NO_ERROR			0	
#define		CIRCUIT_ERROR 		2	
#define		IGBT_NTC_ERROR 		4
#define		BOT_NTC_ERROR  		6
#define		LED_DISPLAY_CTRL	0		

#define SIM_SDI_SDA_RX_PA2()                       {_ifs3=0;_ifs2=1;}  //	{ _sdisdarxps1 = 0;_sdisdarxps0 = 0;}
#define SIM_SDI_SDA_RX_PC2()                       {_ifs3=1;_ifs2=0;}  //	{ _sdisdarxps1 = 1;_sdisdarxps0 = 0;}
#define SIM_SDI_SDA_RX_PB6()                       {_ifs3=1;_ifs2=1;}  //	{ _sdisdarxps1 = 1;_sdisdarxps0 = 1;}
#define SIM_SCK_SCL_PB7()							{_ifs1=0;}	//	{_scksclps=0;}
#define SIM_SCK_SCL_PA0()							{_ifs1=1;}//	{_scksclps=1;}
#define SDA_C	_pac0
#define SDA		_pa0

#define SCL_C   _pac2
#define SCL   	_pa2

#define DatHi()		SDA_C=1

#define	C_DEVICE_ID			0X72	//Slave Address  
#define	C_OPERATION_CMD		0X01	//Command word
#define	C_CALIBRATION_CMD	0x02	//Command word
#define	C_INITSETTING_CMD	0x03	//Command word
#define	C_DEBUG_CMD			0x04	//Command wor

#define	C_NC					0	

extern void IIC_Init();

typedef enum 
{
	NO_ERROR_CODE				=(u8)0,
	ERROR_UVP		  		=(u8)1,	
	ERROR_OCP				=(u8)2, 
	ERROR_OVP				=(u8)3,
	ERROR_IGBT_NTC			=(u8)4,
	ERROR_IGBT_OVER_TMP		=(u8)5,
	ERROR_PAN_NTC			=(u8)6,
	ERROR_PAN_OVER_TMP		=(u8)7,
	ERROR_PHASE				=(u8)8,	//Half-bridge Induction Cooker
	ERROR_SURGE				=(u8)9,
	ERROR_I2C 				=(u8)10

} ErrorCode_TypeDef;



typedef union
{
	struct
	{      
	  u8	p_t_set		:1;		
	  u8	beep		:2;		//		
	  u8	on_off		:2;		//
	  u8	fan			:2;		//
	  u8	undefined	:1;		//
	}flagBit;    	
	u8 m_data;    
}
ControlSet_Flag; //ControlSet_App

typedef union
{
	struct
	{      
	  u8	PowerSetChanged		:1;		
	  u8	VAC_Changed			:1;		//
	  u8	PanMovOut			:1;		//
	  u8	Flag30k				:1;		//
	  u8	PotType				:1;		//
	  u8	PanMovOutCheck		:1;		//
	  u8	PanCheckFlag		:1;		//
	  u8    PowerONFlag    		:1;		//
	}flagBit;    
	u8 m_data;    
}
_FLAG; //FLAG

typedef union
{
	struct
	{      
	  u8	error  			:4;			
  	  u8	NoPan			:1;			//
  	  u8    Undefined		:2;			//
//    u8	PWM_ON_OFF		:1;			//  		
// 	  u8	IIC_CF			:1;			//
 	  u8	Machine_ON_OFF	:1;			//
	}flagBit;    
	u8 m_data;    
}
IH_Status_FLAG;	//IH_Status_APP

typedef union
{
	struct
	{      
  	  u8	PWM_ON_OFF		:1;			//
 	  u8	IIC_CF			:1;			
 	  u8	Machine_ON_OFF	:1;			//
	  u8    mode    		:1;			//
	  u8 	V_I				:1;	
	  u8    PWOER_SET_CHANGE    :1;		
 	  u8    Undefined		:3;			//
	}flagBit;    
	u8 m_data;    
}
_FG_IH_Status0;		


typedef union
{
	struct
	{      
	  u8	Power_OK  		:1;		//
  	  u8	PowerAdd		:1;		//
  	  u8	PowerCutdown	:1;		//
 	  u8	FreLimit		:1;		//
 	  u8	FerMin			:1;		//
 	  u8	FrePhase		:1;		//
 	  u8	VoltageInc		:1;		//
 	  u8	VoltageDec		:1;		//
	}flagBit;    
	u8 m_data;    
}
_POWER_CTRL;

typedef union
{
	struct
	{      
	  u8	LED_Fg  		:1;		//
  	  u8	DebFlag			:1;		//
  	  u8	CurFinFlag		:1;		//calibration mode current AD sample finished
 	  u8	NC3				:1;
 	  u8	NC4				:4;
	}flagBit;    
	u8 m_data;    
}
_DEBUGMODE_CTRL;

//extern vu8	u8_PowerMea_HB,u8_PowerMea_LB;
extern vu8	u8_PowerSetHB_buf,u8_PowerSetLB_buf;
extern vu8	IIC_Cnt;

extern volatile ControlSet_Flag 		ControlSet_App;		
extern volatile IH_Status_FLAG 		IH_Status_APP;		
extern volatile _FLAG 				FLAG;			//
extern volatile _POWER_CTRL 			POWER_CTRL;		//
extern volatile _DEBUGMODE_CTRL		Debug_Mode;		//

extern volatile _FG_IH_Status0  FG_IH_Status;  

void Get_PwoerSet_from_IIC();
void 	IIC_Check(unsigned char Temp_Time_10msCnt);
#endif

/******************* End of file ***************/